package com.zpark.controller;

import com.zpark.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @PackageName: com.zpark.controller
 * @ClassName: UserController
 * @Description:
 * @author: RZS
 * @date: 2023/4/13  8:57
 */
@Controller
public class UserController {

    @RequestMapping("/test.html")
    public String test(){
        return "demo01";
    }

    @RequestMapping("/login.do")
    public ModelAndView login(User user, HttpServletRequest request){
        ModelAndView view = new ModelAndView();
        // 判断用户的用户名和密码是否正确
        if ("admin".equals(user.getUname()) && "root".equals(user.getPwd())) {
            // 登录成功，将用户数据绑定到session对象当中
            HttpSession session = request.getSession();
            session.setAttribute("user", user);

            // 响应到登录成功页面
            view.setViewName("login_success");
        }else{
            // 登录失败，响应到登录失败页面
            view.setViewName("login_error");
        }

        return view;
    }

    @RequestMapping("/update_pwd.do")
    public String updatePwd(){
        return "update_pwd";
    }
}
